﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Presentation
{
    public class TagControlCollection:IList<TagControl>
    {
        private readonly IList<TagControl> innerList = new List<TagControl>();

        private TagBox owner;

        public int Count
        {
            get { return innerList.Count; }
        }

        public bool IsReadOnly
        {
            get { return innerList.IsReadOnly; }
        }

        public TagControl this[int index]
        {
            get { return innerList[index]; }
            set { innerList[index] = value; }
        }

        public TagControlCollection(TagBox _owner)
        {
            owner = _owner;
        }

        public void Add(TagControl tag)
        {
            tag.TagBox = owner;
            innerList.Add(tag);
        }

        public void AddRange(List<TagControl> tags)
        {
            for (int i = 0; i < tags.Count; i++)
            {
                tags[i].TagBox = owner;
                innerList.Add(tags[i]);
            }
        }

        public int IndexOf(TagControl tag)
        {
            return innerList.IndexOf(tag);
        }

        public TagControl[] ToArray()
        {
            TagControl[] tagArray = new TagControl[innerList.Count];
            for (int i = 0; i < innerList.Count; i++)
                tagArray[i] = innerList[i];

            return tagArray;
        }

        public void Insert(int index, TagControl tag)
        {
            tag.TagBox = owner;
            innerList.Insert(index, tag);
        }

        public bool Remove(TagControl tag)
        {
            tag.TagBox = owner;
            return innerList.Remove(tag);
        }

        public void RemoveAt(int index)
        {
            innerList.RemoveAt(index);
        }

        public void Clear()
        {
            innerList.Clear();
        }

        public bool Contains(TagControl tag)
        {
            tag.TagBox = owner;
            return innerList.Contains(tag);
        }

        public void CopyTo(TagControl[] array, int arrayIndex)
        {
            innerList.CopyTo(array, arrayIndex);
        }

        public IEnumerator<TagControl> GetEnumerator()
        {
            return innerList.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
}